//验证码
var code;
function createCode() 
{
	code = "";
	var codeLength = 6; //验证码的长度
	var checkCode = document.getElementById("checkCode");
	var codeChars = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 
			'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
			'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); //所有候选组成验证码的字符，当然也可以用中文的
	for(var i = 0; i < codeLength; i++){
		var charNum = Math.floor(Math.random() * 52);
		code += codeChars[charNum];
	}
	if(checkCode){
		checkCode.className = "code";
		checkCode.innerHTML = code;
	}
}
//注册
function register() { 
	var yhm = $('#yhm').val();
	var password1 = $('#password1').val();
	var password2 = $('#password2').val();
	var yzm = $('#yzm').val();
	yhm = yhm.replace(/\s/g, "");
	password1 = password1.replace(/\s/g, "");
	password2 = password2.replace(/\s/g, "");
	yzm = yzm.replace(/\s/g, "");
	if(yhm==""){$("#yhmyz").html("&nbsp;&nbsp;用户名不能为空！"); return;}else{$("#yhmyz").html("");}
	if(password1==""){$("#passyz").html("&nbsp;&nbsp;密码不能为空！"); return;}else{$("#passyz").html("");}
	if(password2==""){$("#pass1yz").html("&nbsp;&nbsp;验证密码不能为空！"); return;}else{$("#pass1yz").html("");}
	if(password1!=password2){$("#pass1yz").html("&nbsp;&nbsp;两次输入密码不同！"); return;}else{$("#pass1yz").html("");}
	if(yzm==""){$("#yzmyz").html("&nbsp;&nbsp;验证码不能为空！"); return;}else{$("#yzmyz").html("");}
	if(yzm.toUpperCase() != code.toUpperCase()){
	   $("#yzmyz").html("&nbsp;&nbsp;验证码输入有误！");
	   createCode();
	   return;
	}
	$.ajax({
		  type: "post",
		  url: "../qtuser/addUser",
		  data: {
			  'yhm':encode64(yhm),//用户名
			  'password1':encode64(password1)//密码
		  },
		  dataType: "json",
		  success: function(data){
				alert(data.msg);
				if(data.msg=="添加成功！"){
					window.location.href="home.html";
				}
		  }
	  })
}

